package com.example.yiwei.crm.view.frament.menuFragment;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.example.yiwei.crm.R;

import java.util.Calendar;
import java.util.TimeZone;



/**
 * Created by DHN on 2016/12/2.
 */
//主菜单界面
public class home_fragment extends Fragment {
    public static String mYear,mMonth,mDay,mWeek;
    private RadioGroup rg;
    private RadioButton rb1,rb2,rb3,rb4;
    private TextView txt_date,line1,line2,line3,line4;
    Fragment fragment_need_contact,fragment_need_return,fragment_already_return,fragment_already_appointment;
    FragmentManager fragmentManager;
    ViewPager viewPager;
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootview = inflater.inflate(R.layout.frament_first, container, false);
        fragmentManager=getChildFragmentManager();
        viewPager= (ViewPager) rootview.findViewById(R.id.frament_first_viewPager);
//        viewPager.setAdapter(new MyAdapter(fragmentManager));
        txt_date= (TextView) rootview.findViewById(R.id.frm_home_txt_date);
        getDate();
        txt_date.setText( mMonth + "月" + mDay+"日"+" "+"星期"+mWeek);
        rg= (RadioGroup) rootview.findViewById(R.id.frament_first_rg);
        //需联系
        rb1= (RadioButton) rootview.findViewById(R.id.frament_first_rb_need_contact);
        //已预约
        rb2= (RadioButton) rootview.findViewById(R.id.frament_first_rb_already_appointment);
        //需回访
        rb3= (RadioButton) rootview.findViewById(R.id.frament_first_rb_need_return);
        //已回访
        rb4= (RadioButton) rootview.findViewById(R.id.frament_first_rb_already_return);
        line1= (TextView) rootview.findViewById(R.id.line1);
        line2= (TextView) rootview.findViewById(R.id.line2);
        line3= (TextView) rootview.findViewById(R.id.line3);
        line4= (TextView) rootview.findViewById(R.id.line4);
        line1.setTextColor(Color.rgb(127,127,127));
        line2.setTextColor(Color.WHITE);
        line3.setTextColor(Color.WHITE);
        line4.setTextColor(Color.WHITE);
//        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
//            @Override
//            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
//
//            }
//
//            @Override
//            public void onPageSelected(int position) {
//                switch (position) {
//                    case 0:
//                        rb1.setChecked(true);
//                        line1.setTextColor(Color.rgb(127,127,127));
//                        line2.setTextColor(Color.WHITE);
//                        line3.setTextColor(Color.WHITE);
//                        line4.setTextColor(Color.WHITE);
//                        break;
//                    case 1:
//                        rb2.setChecked(true);
//                        line2.setTextColor(Color.rgb(127,127,127));
//                        line1.setTextColor(Color.WHITE);
//                        line3.setTextColor(Color.WHITE);
//                        line4.setTextColor(Color.WHITE);
//                        break;
//                    case 2:
////                        rg.check(R.id.frament_first_rb_need_return);
//                        rb3.setChecked(true);
//                        line2.setTextColor(Color.WHITE);
//                        line3.setTextColor(Color.rgb(127,127,127));
//                        line1.setTextColor(Color.WHITE);
//                        line4.setTextColor(Color.WHITE);
//                        break;
//                    case 3:
//                        rb4.setChecked(true);
//                        line2.setTextColor(Color.WHITE);
//                        line3.setTextColor(Color.WHITE);
//                        line1.setTextColor(Color.WHITE);
//                        line4.setTextColor(Color.rgb(127,127,127));
//                        break;
//
//                }
//            }
//
//            @Override
//            public void onPageScrollStateChanged(int state) {
//
//            }
//        });
//        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(RadioGroup radioGroup, int i) {
//                switch (i) {
//                    case R.id.frament_first_rb_need_contact:
//                        viewPager.setCurrentItem(0,true);
//                        line1.setTextColor(Color.rgb(127,127,127));
//                        line2.setTextColor(Color.WHITE);
//                        line3.setTextColor(Color.WHITE);
//                        line4.setTextColor(Color.WHITE);
//                        break;
//                    case R.id.frament_first_rb_already_appointment:
//                        viewPager.setCurrentItem(1,true);
//                        line2.setTextColor(Color.rgb(127,127,127));
//                        line1.setTextColor(Color.WHITE);
//                        line3.setTextColor(Color.WHITE);
//                        line4.setTextColor(Color.WHITE);
//                        break;
//                    case R.id.frament_first_rb_need_return:
//                        viewPager.setCurrentItem(2,true);
//                        line3.setTextColor(Color.rgb(127,127,127));
//                        line2.setTextColor(Color.WHITE);
//                        line1.setTextColor(Color.WHITE);
//                        line4.setTextColor(Color.WHITE);
//                        break;
//                    case R.id.frament_first_rb_already_return:
//                        viewPager.setCurrentItem(3,true);
//                        line4.setTextColor(Color.rgb(127,127,127));
//                        line2.setTextColor(Color.WHITE);
//                        line3.setTextColor(Color.WHITE);
//                        line1.setTextColor(Color.WHITE);
//                        break;
//                }
//            }
//        });

        return rootview;
    }
    public static String getDate(){
        final Calendar c = Calendar.getInstance();
        c.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
        mYear = String.valueOf(c.get(Calendar.YEAR)); // 获取当前年份
        mMonth = String.valueOf(c.get(Calendar.MONTH) + 1);// 获取当前月份
        mDay = String.valueOf(c.get(Calendar.DAY_OF_MONTH));// 获取当前月份的日期号码
        mWeek = String.valueOf(c.get(Calendar.DAY_OF_WEEK));
        if("1".equals(mWeek)){
            mWeek ="天";
        }else if("2".equals(mWeek)){
            mWeek ="一";
        }else if("3".equals(mWeek)){
            mWeek ="二";
        }else if("4".equals(mWeek)){
            mWeek ="三";
        }else if("5".equals(mWeek)){
            mWeek ="四";
        }else if("6".equals(mWeek)){
            mWeek ="五";
        }else if("7".equals(mWeek)){
            mWeek ="六";
        }
        return mYear + "年" + mMonth + "月" + mDay+"日"+" "+"星期"+mWeek;
    }
//    class MyAdapter extends FragmentPagerAdapter {
//
//        public MyAdapter(FragmentManager fm) {
//            super(fm);
//            // TODO Auto-generated constructor stub
//        }
//
//        @Override
//        public Fragment getItem(int position) {
//            // TODO Auto-generated method stub
//            Fragment fragment = null;
//            switch (position) {
//                case 0:
//                    fragment = new needContactFragment();
//                    break;
//                case 1:
//                    fragment = new alreadyAppointmentFragment();
//                    break;
//                case 2:
//                    fragment = new needReturnFragment();
//                    break;
//                case 3:
//                    fragment = new alreadyReturnFragment();
//                    break;
//
//            }
//            return fragment;
//        }
//
//        @Override
//        public int getCount() {
//            // TODO Auto-generated method stub
//            return 4;
//        }
//
//    }

}
